//
//  YCGoodsTableViewCell.m
//  lianganyuchu
//
//  Created by iMac on 17/2/23.
//  Copyright © 2017年 杭州桑缇电子商务有限公司. All rights reserved.
//

#import "YCGoodsTableViewCell.h"

@interface YCGoodsTableViewCell()
{
    UIView *m_frontView;
}
@end
@implementation YCGoodsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    CGFloat width=kMainScreen_Width-50-kDistance-kSmallDistance;
    [self.backView addShadowWith:CGSizeMake(width, 100)];
    
    self.buttonEdit.layer.borderColor=MAIN_COLOR.CGColor;
    self.buttonEdit.layer.borderWidth=0.5f;
    self.buttonEdit.layer.cornerRadius=2.0f;
    [self.buttonEdit.titleLabel setFont:[UIFont LightFontOfSize:14]];
    
    self.buttonSale.layer.borderColor=MAIN_COLOR.CGColor;
    self.buttonSale.layer.borderWidth=0.5f;
    self.buttonSale.layer.cornerRadius=2.0f;
    [self.buttonSale.titleLabel setFont:[UIFont LightFontOfSize:14]];

    [self.labTitle setFont:[UIFont LightFontOfSize:16]];
    [self.labTitle setTextColor:TEXT_DEEP];
    [self.labPrice setFont:[UIFont LightFontOfSize:14]];
    [self.labPrice setTextColor:RED_COLOR];
    [self.labNum setFont:[UIFont LightFontOfSize:14]];
    [self.labNum setTextColor:TEXT_MIDDLE];
    [self.labNum setAdjustsFontSizeToFitWidth:YES];
    [self.labStatus setFont:[UIFont LightFontOfSize:12]];
    [self.labStatus setTextColor:DISABLE_COLOR];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)buttonSaleClicked:(id)sender {
    if (_index==1) {
        if (_item.is_sell.intValue==1) {
            _item.is_sell=@"0";
        }else if (_item.is_sell.intValue==0){
            _item.is_sell=@"1";
        }
        if (self.saleBlock) {
            self.saleBlock(_item);
        }
    }
    if (_index==3) {
        if (self.addBlock) {
            self.addBlock(_item);
        }
    }
}

- (IBAction)buttonEditClicked:(id)sender {
    if (self.editBlock) {
        self.editBlock(_item);
    }
}

-(void)bindWith:(ItemTable *)item
{
    _item=item;
    [self.labTitle setText:item.name];
    [self.labPrice setText:[NSString stringWithFormat:@"￥%@",item.price]];
    [self.iconView load:item.img];
    [self.labNum setText:[NSString stringWithFormat:@"可售：%@份",item.stock]];
    
    if (_index==1) {
        [self.labStatus setText:@"已下架"];
        [self.labStatus setTextColor:DISABLE_COLOR];
        [self.labStatus setHidden:(item.is_sell.intValue==1)];
        [self.buttonEdit setHidden:NO];
        
        if (item.is_sell.intValue==1) {
            [m_frontView setHidden:YES];
            
            self.buttonEdit.enabled=YES;
            self.buttonEdit.layer.borderColor=MAIN_COLOR.CGColor;
            [self.buttonEdit setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
            
            [self.labTitle setTextColor:TEXT_DEEP];
            [self.labPrice setTextColor:MAIN_COLOR];
            [self.labNum setTextColor:TEXT_MIDDLE];
            
            self.buttonSale.layer.borderWidth=0.5f;
            [self.buttonSale setBackgroundColor:WHITE_COLOR];
            [self.buttonSale setTitle:@"停售" forState:UIControlStateNormal];
            [self.buttonSale setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
            
        }else if (item.is_sell.intValue==0){
            self.buttonEdit.enabled=NO;
            self.buttonEdit.layer.borderColor=DISABLE_COLOR.CGColor;
            [self.buttonEdit setTitleColor:DISABLE_COLOR forState:UIControlStateNormal];
            
            [self.labTitle setTextColor:DISABLE_COLOR];
            [self.labPrice setTextColor:DISABLE_COLOR];
            [self.labNum setTextColor:DISABLE_COLOR];
            
            self.buttonSale.layer.borderWidth=CGFLOAT_MIN;
            [self.buttonSale setBackgroundColor:ORANGE_COLOR];
            [self.buttonSale setTitle:@"恢复售卖" forState:UIControlStateNormal];
            [self.buttonSale setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
            
            if (m_frontView==nil) {
                m_frontView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, W(self.backView), H(self.backView))];
                m_frontView.backgroundColor=WHITE_COLOR;
                m_frontView.alpha=0.5f;
            }
            [self.backView addSubview:m_frontView];
            [m_frontView setHidden:NO];
            
            [self.backView bringSubviewToFront:self.buttonEdit];
            [self.backView bringSubviewToFront:self.buttonSale];
        }

    }
    
    if (_index==3) {
        [self.labStatus setHidden:YES];
        [self.buttonEdit setHidden:YES];
        
        self.buttonSale.layer.borderWidth=CGFLOAT_MIN;
        [self.buttonSale setBackgroundColor:ORANGE_COLOR];
        [self.buttonSale setTitle:@"叫货" forState:UIControlStateNormal];
        [self.buttonSale setTitleColor:WHITE_COLOR forState:UIControlStateNormal];
        
        [self.buttonSale setHidden:(item.added.intValue==1)];
        [self.labNum setText:[NSString stringWithFormat:@"可售：%@份",item.num]];
        
        self.labStatus.hidden=(item.added.intValue==0);
        [self.labStatus setText:@"已叫货"];
        [self.labStatus setTextColor:MAIN_COLOR];
    }
    
}


@end




